<?php
namespace Plu\Library\Models\Tga\Baoming;

use Phalcon\Mvc\Model,
    Phalcon\Db\Column;

class Applicants extends Model {

    public $id;
    public $uid;
    public $appkey;
    public $signupinfo;
    public $signdate;
    public $status;

    public function initialize() {
        $this->setConnectionService('db.baoming');
        //$this->allowEmptyStringValues(array());
    }

    public function getSource() {
        return 'signup_list';
    }

    static public function getItemByUid($appkey, $uid) {
        $item = self::find(array(
            "appkey = :appkey: AND uid = :uid:",
            "bind" => array(
                'appkey' => $appkey,
                'uid'    => $uid
            ),
            "bindTypes" => array(
                'appkey' => Column::BIND_PARAM_STR,
                'uid'    => Column::BIND_PARAM_INT
            )
        ));

        if ($item == false) {
            return [];
        } else {
            return $item->toArray();
        }
    }

    public function insert($appkey, $uid, $createtime, $info) {
        $item = new self;
        $item->uid = $uid;
        $item->appkey = $appkey;
        $item->signupinfo = $info;
        $item->signdate = $createtime;
        $item->status = 1;

        return $item->save();
    }
}
?>
